﻿@using System.Data
@{
    ViewBag.Title = "AddActivityGood";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
    DataTable table = ViewData["sort"] as DataTable;
}

<table style="margin-left: 10px; font-size: 12px;">
    <tr>
        <td colspan="2">
          
                    <label style="font-size: 15px; color: red;">热销商品</label>
               
        </td>
    </tr>
    <tr>
        <td><label>商品分类</label></td>
        <td>
            <select style="width: 230px" id="sort" onchange="getgoods()">
                <option value="0">请选择商品分类</option>
                @{
                    foreach (DataRow row in table.Rows)
                    {
                        <option value="@row["Id"]">@row["Name"]</option>
                    }
                }
            </select>
        </td>
    </tr>
    <tr>
        <td><label>商品名称</label></td>
        <td>
            <select style="width: 400px" id="goods">
                <option value="0">请选择商品</option>
            </select>
        </td>
    </tr>


</table>
<td colspan="2">
    <div class="botton" style="margin-left: 50px;" onclick="edit()">保存</div>
    <div class="botton" style="margin-left: 50px;" onclick="history.go(-1)">取消</div>
</td>
<div style="width: 1000px; height: 40px; margin-top: 200px; "></div>
<script>
    function getgoods() {
        var sid = $("#sort").val();
        if (sid != 0) {
            $.post("@Url.Action("GetGoodInfo")", { sid: sid }, function(data) {
                var obj = JSON.parse(data);
                var str = "";
                for (var i = 0; i < obj.length; i++) {
                    str += "<option value='" + obj[i].Id + "'>" + obj[i].Name + "</option>";
                }
                $("#goods").html(str);
            });
        }
    }

    function edit() {
        var gid = $("#goods").val();
        if (gid != 0) {
            $.post("@Url.Action("EditXpRx")",{gid:gid},function(row) {
               if (row == -1) {
                   alert("该商品已添加，请不要重复添加！");
               } else if (row > 0) {
                   alert("添加成功！");
               } else {
                   alert("操作失败！");
               }
            });
        }
    }
</script>
